﻿using System;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YArchitech.Revit;
using YArchitech.Revit.RevitExtension;
using YJKRevitBase.Math;
using YJKRevitDimensionText.DimCreator;

namespace YJKRevitDimensionText.OneKeyPlanDim.DimesionDataEx
{
	public class DoorWinDataEx
	{
		public DoorWinDataEx(UIApplication uiApp, ElementId id, ElementId hostId)
		{
			this.m_id = id;
			this.m_hostId = hostId;
			this.m_uiApp = uiApp;
			this.m_doc = this.m_uiApp.ActiveUIDocument.Document;
			this.m_familyInstance = (this.m_doc.GetElement(this.m_id) as FamilyInstance);
			this.Init();
		}

		public DoorWinDataEx(UIApplication uiApp, FamilyInstance familyinstance, ElementId hostId)
		{
			this.m_id = familyinstance.Id;
			this.m_familyInstance = familyinstance;
			this.m_hostId = hostId;
			this.m_uiApp = uiApp;
			this.m_doc = this.m_uiApp.ActiveUIDocument.Document;
			this.Init();
		}

		public Line doorWinLine
		{
			get
			{
				return this.m_doorWinLine;
			}
		}

		public Line CheckDoorWinLind()
		{
			XYZ hyendPoint = RevitDocumentExtension.GetEndPoint(this.m_doorWinLine, 0);
			XYZ hyendPoint2 = RevitDocumentExtension.GetEndPoint(this.m_doorWinLine, 1);
			XYZ xyz = (hyendPoint2 - hyendPoint).Normalize();
			XYZ xyz2 = hyendPoint + xyz * UnitUtility.MMToFeet(this.m_dTol);
			XYZ xyz3 = hyendPoint2 - xyz * UnitUtility.MMToFeet(this.m_dTol);
			return YJKLineEx.YJKGetBound(xyz2, xyz3);
		}

		public XYZ vecdoorWin
		{
			get
			{
				return this.m_vecdoorWin;
			}
		}

		public ElementId hostId
		{
			get
			{
				return this.m_hostId;
			}
		}

		public bool bHasHost
		{
			get
			{
				return this.m_bHasHost;
			}
			set
			{
				this.m_bHasHost = value;
			}
		}

		public ElementId DWId
		{
			get
			{
				return this.m_id;
			}
		}

		public bool IsDoor
		{
			get
			{
				return this.m_bDoor;
			}
		}

		public FamilyInstance WDInstance
		{
			get
			{
				return this.m_familyInstance;
			}
		}

		private void Init()
		{
			XYZ xyz = null;
			XYZ xyz2 = null;
			XYZ xyz3 = null;
			if (this.m_familyInstance != null)
			{
				if (DimPublicFunc.GetOpeningPoint(this.m_uiApp, this.m_familyInstance, ref xyz, ref xyz2, ref xyz3))
				{
					this.m_doorWinLine = YJKLineEx.YJKGetBound(xyz2, xyz);
				}
				this.m_vecdoorWin = this.m_familyInstance.FacingOrientation;
				if (this.m_familyInstance.Category.Id.IntegerValue == -2000023)
				{
					this.m_bDoor = true;
				}
			}
		}

		private ElementId m_id;

		private FamilyInstance m_familyInstance;

		private Line m_doorWinLine;

		private XYZ m_vecdoorWin;

		private ElementId m_hostId;

		private bool m_bDoor;

		private UIApplication m_uiApp;

		private Document m_doc;

		private bool m_bHasHost;

		private double m_dTol = 150.0;
	}
}
